package com.coder520.sync_learning.demo.atomic;

import java.util.Date;
import java.util.concurrent.atomic.AtomicReference;

import com.coder520.sync_learning.entity.user.User;
import com.coder520.sync_learning.entity.user.UserEntity;

public class AtomicReferenceTest {
	public static AtomicReference<User> atomicReference=new AtomicReference<User>();
	/**
	 * 原子更新引用类型
	 * 1.Atomic	Reference原子更新引用类型
	 * 2.AtomicReferenceFieldUpdater原子更新引用类型里的字段
	 * 3.AtomicMarkableReference原子更新带有标记位的引用类型。：可以原子更新一个布尔类的标记位和引用类型。构造方法是：Atomic	MarkableReference(V initialRef,Boolean initialMark);

	 * @param args
	 *	2018年6月15日
	 */
	public static void main(String[] args) {
		User user=new User(1, "zhao", "qwerty", new Date());
		atomicReference.set(user);
		User updater=new User(2,"li","zxcvbn",new Date());
//		更新引用类型
		atomicReference.compareAndSet(user, updater);
		atomicReference.get().setUserName("wangwu");
		System.out.println(atomicReference.get().getId());
		System.out.println(atomicReference.get().getUserName());
		
		System.out.println(atomicReference.get().getPassword());
	}
}
